package kaalanshare;

import java.io.*;
import java.net.InetAddress;


/**
 * Created with IntelliJ IDEA.
 * User: twin
 * Date: 21.04.12
 * Time: 23:04
 * To change this template use File | Settings | File Templates.
 */
public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {

        if (args.length > 0) {
            switch (args[0]) {
                //getFile
                case "-g": {
                    if (args.length < 3) {
                        System.out.println("not enough args");
                    } else {
                        FileReceiver.getFileFromHost(args[1], args[2]);
                    }
                    break;
                }
                //addFile
                case "-a": {
                    if (args.length < 3) {
                        System.out.println("not enough args");
                    } else {
                        if (!args[1].equals("s")) {
                            FolderStructure.cpShareFile(new File(args[1]), new File(args[2]));
                        } else {
                            FolderStructure.lnShareFile(args[3], args[2]);
                        }
                    }
                    break;
                }
                //showFiles
                case "-s": {
                    NetFolderBuilder netFiles = new NetFolderBuilder();
                    Thread netFolderBuilder = new Thread(netFiles);
                    netFolderBuilder.start();
                    try {
                        netFolderBuilder.join();
                        synchronized (NetFolderBuilder.class) {
                            for (InetAddress addr : netFiles.map.keySet()) {
                                System.out.println("host " + addr.getHostAddress());
                                System.out.println(netFiles.map.get(addr).printFolderStructure());
                                System.out.println();
                            }
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                    }
                }
            }

        }
    }

//


}





